home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 12600 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: druid.borland.com!usenet
  2. From: pete@borland.com (Pete Becker)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: pointer questions
  5. Date: 20 Mar 1996 20:27:37 GMT
  6. Organization: Borland International
  7. Message-ID: <4ippnq$irp@druid.borland.com>
  8. References: <4ifatf$5a8u@uvaix3e1.comp.UVic.CA> <4injoe$qcp@druid.borland.com> <31502C81.1AB6@datalytics.com>
  9. NNTP-Posting-Host: pbecker.borland.com
  10. Mime-Version: 1.0
  11. Content-Type: Text/Plain; charset=ISO-8859-1
  12. X-Newsreader: WinVN 0.99.5
  13.  
  14. In article <31502C81.1AB6@datalytics.com>, stew@datalytics.com says...
  15. >
  16. >Pete Becker wrote:
  17. >> 
  18. >> In article <4ifatf$5a8u@uvaix3e1.comp.UVic.CA>, cgesy@uvaix.uvic.ca says...
  19. >> >
  20. >> >What does the following statement do/mean? :
  21. >> >
  22. >> >     ((searchItem&) *this)._refCount++;   //searchItem is the class name
  23. >> 
  24. >> It tells the compiler to pretend that the 'this' pointer actually points to 
  25. an
  26. >> object of type searchItem, and to increment the member of that object named
  27. >> _refCount.
  28. >
  29. >More to the point, dereferencing this (*this in the example) 
  30. >results in an object of whatever type this points to.
  31.  
  32. Be a little careful here: *this is not an object, but can be used to access the 
  33. object that 'this' points to.
  34.  
  35. >  That 
  36. >object is then cast to be a reference to class searchItem.  This 
  37. >cast is only permissible if this points to a class for which a 
  38. >conversion to searchItem* is available (ARM 5.4).
  39.  
  40. Yes, but this is a bit misleading, since wild pointer casts are usually 
  41. permitted. In particular, if searchItem has no relationship whatsoever with the 
  42. type that 'this' points to, the cast to searchItem* is legal. Don't make the 
  43. mistake of assuming there is any safety mechanism here. That's why I used the 
  44. word "pretend". If you write code that does this you better be sure you've 
  45. checked all your code paths to guarantee that this cast is safe. The compiler 
  46. will not enforce safety for you here.
  47.     -- Pete
  48.  
  49.